<?php
require ("D:/zhuaqu/include.php");
$url="http://img3.laibafile.cn/getimgXXX/1/3/photo1/2012/1/31/middle/85894484_22338672_middle.jpg";
$Referer="http://bbs.tianya.cn/post-travel-388531-1.shtml";
//$url="http://bbs.longsunhd.com/reset.php";
$url=preg_replace("/\s*http\:\/\/.*http\:\/\//isx","http://",urldecode($url));
preg_match("/http\:\/\/(.*)\//Uisx",$url,$nn);$host=$nn[1];
$url=str_replace("BAIFENHAO","%",$url);

$haveReferer=1;
if(preg_match("/sinaimg\.cn/Uisx",$url)){
  $haveReferer=0;
}

if(preg_match("/39\.com/Uisx",$url)){
  $cookie="_wt_session_refer_cookie=http%253A%252F%252Fwww.39.net%252F; Hm_lpvt_ab2e5965345c61109c5e97c34de8026a=1350459594308; Hm_lpvt_1827105cf5cfac624c8dbf5159abfdb4=1350459576311; onlineId=4770284101207144433; area_info=CN450100|%D6%D0%B9%FA|%B9%E3%CE%F7|%C4%CF%C4%FE%CA%D0|%B5%E7%D0%C5; Hm_lvt_ab2e5965345c61109c5e97c34de8026a=1350459575708; Hm_lvt_1827105cf5cfac624c8dbf5159abfdb4=1350459576311";
}

if(preg_match("/photo\.sina\.com\.cn/Uisx",$url)){
  $cookie="U_TRS1=0000002a.5ede4b18.51a9ace5.29e7cc12; U_TRS2=0000002a.5eeb4b18.51a9ace5.a6fa6e22; UOR=,club.edu.sina.com.cn,; Apache=5411857267557.991.1370074365751; SINAGLOBAL=5411857267557.991.1370074365751; ULV=1370074365762:1:1:1:5411857267557.991.1370074365751:";
}

if(preg_match("/qq\.com/Uisx",$url)){
  $cookie="pgv_pvid=6712437708; pgv_info=ssid=s873852037; qqmusic_uin=12345678; qqmusic_key=12345678; qqmusic_fromtag=6; pt2gguin=o1173550923; uin=o1173550923; skey=@jtHUrXOcH; ptisp=ctc; RK=S0aa0gQfTx; o_cookie=1173550923";
}

$cookie=($cookie!="")?"\r\nCookie: ".trim($cookie)."":"";
$nr=curlbase($url,$cookie,$Referer);
echo $nr;



function whost($str){
    preg_match_all("/http\:\/\/([^\/]+)/",$str,$nn);
    $whost=$nn[1][0];
    return $whost;
}

/*
GET http://img3.laibafile.cn/getimgXXX/1/3/photo1/2012/1/31/middle/85894484_22338672_middle.jpg HTTP/1.1
Accept: * / *
Referer: http://bbs.tianya.cn/post-travel-388531-1.shtml
Accept-Language: zh-CN
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1; WOW64; Trident/5.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C; .NET4.0E)
Accept-Encoding: gzip, deflate
Proxy-Connection: Keep-Alive
If-Modified-Since: Fri, 21 May 2010 06:21:07 GMT
Host: img3.laibafile.cn
Pragma: no-cache
*/

function curlbase($url,$cookie="",$Referer=""){
    static $cookie;
    $host=whost($url);
    $Referer=($Referer=="")?"http://{$host}/":$Referer;
	$timeout=15;
    $ch = curl_init();
    curl_setopt ($ch, CURLOPT_URL, $url);
	//curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
	curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1; WOW64; Trident/5.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C; .NET4.0E)");
	//curl_setopt($ch, CURLOPT_HEADER, 0);
	//curl_setopt($ch, CURLOPT_POST, 1);
	//curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
    //curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
	/*if(preg_match("/multipart/Uisx",$post)){
		curl_setopt($ch, CURLOPT_VERBOSE, 1);
		curl_setopt( $ch, CURLOPT_HTTPHEADER, array("Content-Type: multipart/form-data; boundary=$boundary"));
		curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
	}*/

	if($Referer!="") curl_setopt($ch, CURLOPT_REFERER, $Referer);
	if($cookie!="") curl_setopt($ch, CURLOPT_COOKIE, $cookie);
	//if($Querystring!=""&&$uu[1][0]=="POST"){
        //curl_setopt($ch, CURLOPT_HTTPHEADER, array('Expect:'));
        //curl_setopt($ch, CURLOPT_POSTFIELDS, $Querystring);
    //}
	    curl_setopt($ch, CURLOPT_HTTPHEADER, array(
		'Content-Type: application/json; charset=utf-8',
        'X-Requested-With: XMLHttpRequest',
        'Accept: application/json, text/javascript, */*; q=0.01',
        'Accept-Language: zh-CN',
        'Accept-Encoding: gzip, deflate',
		'Proxy-Connection: Keep-Alive',
		'If-Modified-Since: Fri, 21 May 2010 06:21:07 GMT',
		'Pragma: no-cache',
        'Connection: Keep-Alive',
    ));
    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
    ob_start();
    $result=curl_exec($ch);
    curl_close($ch);
    $result = ob_get_contents();
    ob_end_clean();

    //preg_match("/set\-cookie\:\s*([^\s]*)/",$result,$nn);$cookie=$nn[1];
    //preg_match("/(^.*)(?:\r\n\r\n|\n\n)(.*?)$/Uis", $result, $nn);
    //$result = $nn[2];
    if (@gzinflate(substr($result, 10))) {
        $result = gzinflate(substr($result, 10));
    }
	return $result;
}
?>